<template>
    <div class="container">
        <ul class="tabs">
            <li
                class="tab"
                :class="{ active: index == active }"
                v-for="(item, index) in tabList"
                @click="onClick(index)"
                :key="index">
                {{ item.title }}
                <div class="tab_sub">{{ item.sub }}</div>
            </li>
        </ul>

        <!-- 在这里添加你的tab内容区域 -->
        <div
            class="tab-content"
            v-for="item in dataList"
            :key="item.title">
            <p class="company">
                <img
                    :src="item.url"
                    class="avatar"
                    alt="" />
                {{ item.companyName }}
            </p>
            <div class="card">
                <p class="card_money">
                    {{ item.money }}
                </p>
                <div class="card_info">
                    <div>{{ item.title }}</div>
                    <div class="card_info_sub">{{ item.sub }}</div>
                </div>
                <div
                    class="card_btn"
                    @click="useClick(item)">
                    使用
                </div>
            </div>
        </div>
    </div>
</template>
<script>
export default {
    data() {
        return {
            active: 0,
            tabList: [
                { title: '券', sub: '' },
                { title: '红包', sub: '￥20.5' },
                { title: '卡', sub: '会员身份' },
                { title: '充值金', sub: '￥1' },
                { title: '其他', sub: '+18' },
            ],
            dataList: [
                {
                    money: '388',
                    companyName: 'iPhone企业店',
                    title: '商品优惠券',
                    sub: '限该店铺内指定商品可用',
                },
            ],
        };
    },
    mounted() {
        this.onClick(0); //初始化请求第一个
    },
    methods: {
        // 点击对用tab，请求数据
        onClick(index) {
            this.active = index;
            console.log(index);

            this.$http.post('/api/my/list', { activeNum: this.active }).then(res => {
                if (res.data.success) {
                    this.dataList = res.data.data;
                }
            });
        },
        // 点击使用
        useClick(item) {
            // 去身份验证页面
            this.$router.push({
                path: '/authentication',
                query: { item: item }, //传参
            });
        },
    },
};
</script>
<style lang="scss" scoped>
p {
    margin: 0;
}
.container {
    background-color: #f4f4f4;
}
.tabs {
    display: flex;
    list-style-type: none;
    padding: 15px;
    justify-content: space-between;
    .tab {
        cursor: pointer;
        padding: 10px 0;
        position: relative;
        // width: 50px;
        flex: 1;
        font-weight: 600;
        &_sub {
            font-size: 12px;
            color: gray;
            font-weight: normal;
            margin-top: 4px;
        }

        /* ... 其他原有CSS样式 ... */
    }
    .tab:not(:last-child)::after {
        content: '';
        width: 0.8px;
        height: 30px;
        background-color: #aaa;
        position: absolute;
        right: 0;
        top: 18px;
    }
    .active {
        color: #d91c28; /* 添加这一行，使激活状态下的tab字体变为红色 */
        .tab_sub {
            color: #d91c28;
        }
    }
}

.tab-content {
    padding: 8px;
    .company {
        font-weight: bold;
        font-size: 18px;
        display: flex;
        align-items: center;
        margin-bottom: 8px;
        .avatar {
            width: 20px;
            height: 20px;
            margin-right: 4px;
        }
    }
    .card {
        background-color: #fff;
        border-radius: 8px;
        display: flex;
        padding: 24px 8px;
        gap: 12px;
        .use_btn {
            margin-left: auto;
        }
        &_money {
            font-size: 24px;
            color: #d91c28;
            font-weight: bold;
            &::before {
                content: '￥';
                font-size: 16px;
                font-weight: normal;
            }
        }
        &_info {
            font-weight: bold;
            text-align: left;
            &_sub {
                font-weight: normal;
                font-size: 12px;
                color: gray;
                margin-top: 4px;
            }
        }
        &_btn {
            border: 1px solid #d91c28;
            color: #d91c28;
            height: 30px;
            line-height: 30px;
            width: 60px;
            border-radius: 20px;
            margin-left: auto;
            font-size: 14px;
        }
    }
}
</style>
